
/**
 *@描述：日志管理
 *@作者：顾云飞
 *@创建时间：2023/1/17
 *@最后修改时间：2023/1/18
 */
 import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
 import type { ActionType, ProColumns } from '@ant-design/pro-components';
 import { ProTable, TableDropdown } from '@ant-design/pro-components';
 import { Space, Tag,Table} from 'antd';
 import { useRef } from 'react';
 import request from 'umi-request';
 
 type GithubIssueItem = {
   url: string;
   id: number;
   number: number;
   title: string;
   labels: {
     name: string;
     color: string;
   }[];
   state: string;
   comments: number;
   created_at: string;
   updated_at: string;
   closed_at?: string;
 };
 
 const columns: ProColumns<GithubIssueItem>[] = [
 //   {
 //     dataIndex: 'index',
 //     valueType: 'indexBorder',
 //     width: 48,
 //   },
    {
        title: '访问时间',
        dataIndex: 'visit_time',
        copyable: true,
        ellipsis: true,
        hideInSearch: true
    },
    {
        title: '日志级别',
        dataIndex: 'level',
        copyable: true,
        ellipsis: true,
        hideInSearch: true,
    },
    {
        title: '日志类型',
        dataIndex: 'type',
        valueType: 'select'
    },
    {
        title: '日期区间',
        key: 'dateRange',
        dataIndex: 'createdAtRange',
        valueType: 'dateRange',
        hideInTable: true,
    },
    {
        title: '访问IP',
        key: 'visit_ip',
        dataIndex: 'created_at',
        valueType: 'date',
        hideInSearch: true,
    },
    {
        title: '用户名',
        key: 'username',
        dataIndex: 'created_at',
    },
    {
        title: '日志内容',
        key: 'content',
        dataIndex: 'created_at'
    }
 ];
 
 const LogList = () => {
   const actionRef = useRef<ActionType>();
   return (
     <ProTable<GithubIssueItem>
       columns={columns}
    //    rowSelection={{
    //      selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT]
    //    }}
       actionRef={actionRef}
       cardBordered
       request={async (params = {}, sort, filter) => {
         console.log(sort, filter);
         return request<{
           data: GithubIssueItem[];
         }>('https://proapi.azurewebsites.net/github/issues', {
           params,
         });
       }}
       editable={{
         type: 'multiple',
       }}
       columnsState={{
         persistenceKey: 'pro-table-singe-demos',
         persistenceType: 'localStorage',
         onChange(value) {
           console.log('value: ', value);
         },
       }}
       rowKey="id"
       search={{
         labelWidth: 'auto',
       }}
       options={{
         setting: {
           listsHeight: 400,
         },
       }}
       form={{
         // 由于配置了 transform，提交的参与与定义的不同这里需要转化一下
         syncToUrl: (values, type) => {
           if (type === 'get') {
             return {
               ...values,
               created_at: [values.startTime, values.endTime],
             };
           }
           return values;
         },
       }}
       tableAlertOptionRender={() => {
         return (
           <Space size={16}>
             <a>批量删除</a>
             <a>批量禁用</a>
             <a>审核通过</a>
           </Space>
         );
       }}
       pagination={{
         pageSize: 5,
         onChange: (page) => console.log(page),
       }}
       dateFormatter="string"
       headerTitle="批量操作"
     />
   );
 };
 export default LogList